<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>品牌管理</li>
    <li>添加</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>品牌信息</span></div>
  <ul class="forminfo">
    <li>
      <label>品牌名称</label>
      <input name="" type="text" class="dfinput" />
      <i>必填，不能超过50个字符</i>
    </li>
    <li>
      <label>状态</label>
      <select class="dfselect">
          <option value="1">可用</option>
          <option value="0">不可用</option>
        </select>
      <i>必选</i>
    </li>
    <li>
      <label>创建人</label>
      <input name="createId" type="hidden" th:value="${session.user.uid}"/>
<!--      <input name="createId" type="hidden" th:value="2"/>-->
      <input name="uName" type="text" th:value="${session.user.uname}" readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>创建时间</label>
<!--      <input name="" type="text" value="2017-11-18 15:36:10" readonly="readonly" class="roinput" />-->
      <input name="createTime" id="createTime" type="text"  readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>&nbsp;</label>
      <input name="" type="button" class="btn btn_yes" value="确定" onclick="window.location.href='/purchase/brandList'"/>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="" type="button" class="btn" value="返回" onclick="window.location.href='/purchase/brandList'"/>
    </li>
  </ul>
</div>

<script type="text/javascript">
  //生成当前时间
  $(function (){

    var nowTime = new Date();
    var year = nowTime.getFullYear();
    var month = nowTime.getMonth()+1;
    var day = nowTime.getDate();
    var hour = nowTime.getHours();
    var minutes = nowTime.getMinutes();
    var second = nowTime.getSeconds();
    if(month>0 && month<10){
      month = "0"+month;
    }
    if(day>0 && day<10){
      day = "0"+day;
    }
    if(hour>0 && hour<10){
      hour = "0"+hour;
    }
    if(minutes>0 && minutes<10){
      minutes = "0"+minutes;
    }
    if(second>0 && second<10){
      second = "0"+second;
    }
    var nowDate = year+"-"+month+"-"+day+" "+hour+":"+minutes+":"+second;

    $("#createTime").val(nowDate);
  })

//增加品牌
  $(".btn_yes").click(function () {
    var brandName=$(".dfinput").val().trim();
    if (brandName.replace(/(^\s*)|(\s*$)/g, "") !== ""){
      var brandStatus=$('.dfselect option:selected').val();
      var createTime=$("#createTime").val();
      var createId=$('input[name="createId"]').val();
      $.ajax({
        url: "/brand/addBrand",
        async: false,
        type: "POST",
        data: {brandName:brandName,brandStatus:brandStatus,createTime:createTime,createId:createId},
        dataType: "json",
        success: function (result) {
          if (result=1){
            alert("添加成功")
          }else {
            alert("添加失败")
          }
        }
      })
    }else {
      alert("请输入正确属性");
    }
  })
</script>
</body>
</html>
